package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.pojo.Card;
import com.woniu.pojo.Level;
import com.woniu.service.ICardService;
import com.woniu.service.ILevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xie
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/level")
@Api(tags = "会员等级管理")
public class LevelController extends BaseController{
    @Autowired
    private ILevelService service;

    @ApiOperation("查询所有")
    @GetMapping
    public Result queryAll(){
        List<Level> list = service.list();
        return toDataResult(list);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过id查找")
    public Result queryById(@PathVariable String id){
        Level level = service.getById(id);
        return toDataResult(level);
    }

    @PostMapping
    @ApiOperation("增加")
    public Result add(@RequestBody Level level){
        boolean flag = service.save(level);
        return toResult(flag);
    }

    @PutMapping
    @ApiOperation("修改")
    public Result modify(@RequestBody Level level){
        boolean flag = service.updateById(level);
        return toResult(flag);
    }

    @DeleteMapping("/{Id}")
    @ApiOperation("删除")
    public Result delete(@PathVariable String Id){
        boolean flag = service.removeById(Id);
        return toResult(flag);
    }
}
